<template>
  <div class="container">
    <div class="section">
      <h2 class="title">
        会员权益设置
      </h2>
      <el-form :model="form" :rules="rules">
      <el-form-item label="会员礼包:" :label-width="formLabelWidth" prop="memberBenefitOne" >
        <tinymce
          v-model="form.memberBenefitOne"
          id="memberBenefitOne"
          :min-height="750"
          :width="760"
        />
      </el-form-item>
      <el-form-item label="分享赚钱:" :label-width="formLabelWidth" prop="memberBenefitTwo" >
        <tinymce
          v-model="form.memberBenefitTwo"
          id="memberBenefitTwo"
          :min-height="750"
          :width="760"
        />
      </el-form-item>
      <el-form-item label="整形保险券:" :label-width="formLabelWidth"  prop="memberBenefitThree">
        <tinymce
          v-model="form.memberBenefitThree"
          id="memberBenefitThree"
          :min-height="750"
          :width="760"
        />
      </el-form-item>
      <el-form-item label="保障券:" :label-width="formLabelWidth" prop="memberBenefitFour" >
        <tinymce
          v-model="form.memberBenefitFour"
          id="memberBenefitFour"
          :min-height="750"
          :width="760"
        />
      </el-form-item>
      <el-form-item label="极速退款:" :label-width="formLabelWidth" prop="memberBenefitFive" >
        <tinymce
          v-model="form.memberBenefitFive"
          id="memberBenefitFive"
          :min-height="750"
          :width="760"
        />
      </el-form-item>
      <el-form-item label="VIP客服:" :label-width="formLabelWidth" prop="memberBenefitSix">
      <tinymce
        v-model="form.memberBenefitSix"
        id="memberBenefitSix"
        :min-height="750"
        :width="760"
      />
      </el-form-item>
      <el-form-item label="优先预约:" :label-width="formLabelWidth" prop="memberBenefitSeven" >
          <tinymce
            v-model="form.memberBenefitSeven"
            id="memberBenefitSeven"
            :min-height="750"
            :width="760"
          />
        </el-form-item>
      <el-form-item label="大额优惠券:" :label-width="formLabelWidth" prop="memberBenefitEight" >
          <tinymce
            v-model="form.memberBenefitEight"
            id="memberBenefitEight"
            :min-height="750"
            :width="760"
          />
        </el-form-item>
      <el-form-item label="补贴提速:" :label-width="formLabelWidth" prop="memberBenefitNine" >
        <tinymce
          v-model="form.memberBenefitNine"
          id="memberBenefitNine"
          :min-height="750"
          :width="760"
        />
      </el-form-item>
<!--      <el-form-item label="权益十:" :label-width="formLabelWidth" prop="memberBenefitTen" >-->
<!--        <tinymce-->
<!--          v-model="form.memberBenefitTen"-->
<!--          id="10"-->
<!--          :min-height="750"-->
<!--          :width="760"-->
<!--        />-->
<!--      </el-form-item>-->
      </el-form>

      <div class="sub-btn">
        <el-button type="primary"
                   size="medium "
                   @click="save_form()">保存</el-button>
      </div>
    </div>
  </div>

</template>
<script>
  import { getGroup, groupSetting } from '../../api/group'
  import tinymce from '@/components/Tinymce'
  import { getVipBenefit, saveVipBenefit } from '../../api/vipSetting'
  export default {
    components: {
      tinymce,
    },
    data () {
      return {
        formLabelWidth: '120px',
        form_data: {
          "startGroupLimitHour": 0,
          "startGroupLimitMinute": 0,
          "finishGroupLimitHour": 0,
          "finishGroupLimitMinute": 0,
          "finishGroupLimitPersonNum": 0
        },
        num: '',
        form:{
          memberBenefitOne: null,
          memberBenefitTwo: null,
          memberBenefitThree: null,
          memberBenefitFour: null,
          memberBenefitFive: null,
          memberBenefitSix: null,
          memberBenefitSeven: null,
          memberBenefitEight: null,
          memberBenefitNine: null,
          memberBenefitTen: null,
        },
        rules: {
          memberBenefitOne: [{ required: true, message: '请输入会员礼包', trigger: 'blur' }],
          memberBenefitTwo: [{ required: true, message: '请输入分享赚钱', trigger: 'blur' }],
          memberBenefitThree: [{ required: true, message: '请输入整形保障券', trigger: 'blur' }],
          memberBenefitFour: [{ required: true, message: '请输入保障券', trigger: 'blur' }],
          memberBenefitFive: [{ required: true, message: '请输入急速退款', trigger: 'blur' }],
          memberBenefitSix: [{ required: true, message: '请输入VIP客服', trigger: 'blur' }],
          memberBenefitSeven: [{ required: true, message: '请输入优先预约', trigger: 'blur' }],
          memberBenefitEight: [{ required: true, message: '请输入大额优惠券', trigger: 'blur' }],
          memberBenefitNine: [{ required: true, message: '请输入补贴提速', trigger: 'blur' }],
        }
      }
    },
    methods: {
      //保存
      save_form () {
        if(this.checkInfo()){
          saveVipBenefit(this.form).then((result) => {
            let res = result.data
            if (res.code === 0) {
              this.$message({
                type: 'success',
                message: '设置成功!'
              });
            } else {
              this.$message.error(res.msg);
            }
          }).catch((err) => {
            this.$message.error('服务器网络错误，请稍后重试');
          });
        }else {
          // 弹出错误框
          this.$message({
            showClose: true,
            message: '请填写必要参数',
            type: 'error'
          })
        }

      },
      //获取信息
      get_Setting () {
        getVipBenefit().then((result) => {
          let res = result.data
          if (res.code === 0) {
            this.form = res.data
          } else {
            this.$message.error(res.msg);
          }
        }).catch((err) => {
          this.$message.error('服务器网络错误，请稍后重试');
        });
      },
      // 检查参数
      checkInfo() {
        return !(!this.form.memberBenefitOne ||
          !this.form.memberBenefitTwo ||
          !this.form.memberBenefitThree ||
          !this.form.memberBenefitFour ||
          !this.form.memberBenefitFive ||
          !this.form.memberBenefitSix ||
          !this.form.memberBenefitSeven ||
          !this.form.memberBenefitEight ||
          !this.form.memberBenefitNine )
      },
    },
    created () {
      this.get_Setting()
    },

  }
</script>

<style lang="less" scoped>
  .container {
    padding: 20px;
    .section {
      .title {
        width: 120px;
        height: 30px;
        background-color: #409eff;
        line-height: 30px;
        font-size: 16px;
        text-align: center;
        color: #fff;
        box-shadow: 1px 1px 30px rgba(0, 0, 0, 0.1);
        margin-bottom: 20px;
      }
      .info {
        margin-left: 40px;

        .list-item {
          margin-bottom: 20px;
          color: #666;
          .tip {
            font-size: 16px;
            display: inline-block;
            vertical-align: middle;
            width: 130px;
            text-align: right;
          }
          .content {
            display: inline-block;
            vertical-align: middle;
          }
        }
      }
      .sub-btn {
        width: 100px;
        margin: 120px auto;
      }
    }
  }
</style>
